package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

//本类是用来测试修改操作的演示demo
public class TestUpdate {
    //将location表中id为5的记录中的name值修改为'魔之国度'
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/tedu?useUnicode=true&characterEncoding=utf8";
        String user = "root";
        String pwd = "root";
        conn = DriverManager.getConnection(url,user,pwd);
        String sql = "UPDATE location SET name = '魔之国度' where id =5";
        ps = conn.prepareStatement(sql);
        int rows = ps.executeUpdate();
        System.out.println(rows > 0 ? "修改" + rows + "条记录成功!" : "修改失败!");
        ps.close();
    }
}
